import React, { Component } from 'react'
import s from './WheelSurfIndex.less'
import request from "../utils/request";
import moment from 'moment';
import { hashHistory } from "react-router";
export default class WheelSurfIndex extends Component {

    constructor(props) {
        super(props)

        this.state = {
            shopId: '',
            card_id: '',
            /* 抽奖次数 */
            times: '',
            lastTime: ''
        }
    }
    componentWillMount() {
        document.title = '幸运抽奖'
    }
    componentDidMount() {
        this.getTimes()
    }

    getTimes = () => {
        let shopId = 'sixun_000153'
        let card_id = '13229138791'
        request("/bigWheel/" + shopId, {
            params: {
                card_id: card_id
            },
            method: "get"
        }).then(res => {
            if (res.data.success === true) {
                console.log('可剩余的抽奖', res.data)

                this.setState(
                    {
                        shopId: shopId,
                        card_id: card_id,
                        /* 抽奖次数 */
                        times: res.data.times,
                        lastTime: res.data.lastTimestamp
                    }
                );
            } else {
                //请求失败
                Toast.info("网络繁忙，请稍后重试", 2);
            }
        })
    }

    wheelItem = (lastTime) => {
        const { times } = this.state
        for (let i = 0; i < Number(times); i++) {
            return (
                <div className={s['wheelItem']}
                 onClick = {
                    () => {
                        hashHistory.push({
                            pathname: 'wheelsurf/index',
                            query: {
                              card_id: this.state.card_id,
                              shopId: this.state.shopId,
                            }
                        })
                    }
                 }
                >
                    <div className={s['left']}>
                        <div>幸运抽奖</div>
                        <div>活动时间：2020.11.01至{moment(lastTime).format('YYYY.MM.DD')}</div>

                    </div>
                    <div className={s['right']}>
                        马上抽奖
                    </div>
                </div>
            )
        }
    }
    render() {
        const { times } = this.state
        return (
            <div className={s['wheelWrap']}>
                {this.wheelItem(times)}
                {times == '' || times == '0' ?  <div className={s['noData']}>没有抽奖券</div> :''}
            </div>
        )
    }
}
